//
//  MessageEmptyView.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/6/19.
//

#import "MessageEmptyView.h"

@interface MessageEmptyView()
@property(nonatomic,strong)UIImageView *logoImageView;
@property(nonatomic,strong)UILabel *tipLabel;
@end

@implementation MessageEmptyView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.currentAvailableWidth = frame.size.width;
        self.currentAvailableHeight = frame.size.height+kYM_NAVIGATIONBAR_HEIGHT;
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    CGFloat top = (self.currentAvailableHeight-kYM_NAVIGATIONBAR_HEIGHT-40-138)/2.0;
    if(top > 134){
        top = 134;
    }
    __weak typeof(self)self_weak_ = self;
    self.backgroundColor = [UIColor whiteColor];
    UIImageView *logoImageView = [[UIImageView alloc]init];
    logoImageView.image = [UIImage imageNamed:@"empty_logo"];
    [self addSubview:logoImageView];
    [logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(@138);
        make.top.mas_equalTo(top);
        make.centerX.mas_equalTo(self_weak_);
    }];
    self.logoImageView = logoImageView;
    
    UILabel *tipLabel = [[UILabel alloc]init];
    tipLabel.font = JPUIFontPingFangSCRegular(14);
    tipLabel.textColor = KFontGrayColor;
    tipLabel.textAlignment = NSTextAlignmentCenter;
    tipLabel.text = @"暂时还没有消息...";
    [self addSubview:tipLabel];
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(logoImageView.mas_bottom).offset(20);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(self_weak_.currentAvailableWidth-32);
        make.centerX.mas_equalTo(self_weak_);
    }];
    self.tipLabel = tipLabel;
}

-(void)refreshWidth{
    __weak typeof(self)self_weak_ = self;
    CGFloat top = (self.currentAvailableHeight-kYM_NAVIGATIONBAR_HEIGHT-40-138)/2.0;
    if(top > 134){
        top = 134;
    }
    [self.logoImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(top);
    }];
    [self.tipLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self_weak_.logoImageView.mas_bottom).offset(20);
        make.width.mas_equalTo(self_weak_.currentAvailableWidth-32);
    }];
}

@end
